﻿Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls


Public Class Dispatch

    Private Sub Dispatch_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        My.Settings.DispatchPos = Me.Location

    End Sub





    Private Sub Dispatch_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.Opacity = 0.95

        Me.Location = My.Settings.DispatchPos

        DateEdit1.DateTime = Date.Today
        TimeEdit1.Time = "08:00"
        TimeEdit2.Time = "09:00"

        'Connection to Cadis DB Server
        Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection(My.Settings.CADISConnectionString)
        Dim cmd As New System.Data.SqlClient.SqlCommand
        Dim reader As SqlClient.SqlDataReader = Nothing

        cmd.CommandType = System.Data.CommandType.Text
        cmd.Connection = sqlConnection1
        sqlConnection1.Open()

        'Get all technicien
        cmd.CommandText = "SELECT EAEMNM, EAREGN, EAEMNO FROM F0010  WHERE EAREGN <> '' ORDER BY EAEMNM"

        reader = cmd.ExecuteReader()

        While reader.Read
            ComboBox1.Items.Add(Trim(reader(0).ToString) & " / " & Trim(reader(1).ToString) & " / " & Trim(reader(2).ToString))
        End While

        sqlConnection1.Close()

    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        Dim s As Array
        s = Split(ComboBox1.SelectedItem.ToString, "/")
        If Trim(s(0)) <> "" Then
            DispatchAUF(OrderNb.Text, Trim(s(1)), Trim(s(2)))

            AddMessage("Order new dispatched ... " & OrderNb.Text & " / " & Trim(s(1)) & " / " & Trim(s(2)))

            Me.Close()
        End If

    End Sub

    Private Sub TimeEdit1_EditValueChanged(sender As Object, e As System.EventArgs) Handles TimeEdit1.EditValueChanged
        If TimeEdit1.Time > TimeEdit2.Time Then TimeEdit2.Time = TimeEdit1.Time.AddHours(1)
    End Sub


    Private Sub TimeEdit2_TextChanged(sender As Object, e As System.EventArgs) Handles TimeEdit2.TextChanged
        If TimeEdit1.Time > TimeEdit2.Time Then TimeEdit1.Time = TimeEdit2.Time.AddHours(-1)
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
End Class